package com.citibank.dashboard.entity.dao;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class GenericDAO<T> implements DAOInterface<T> {

	static Logger logger = Logger.getLogger(GenericDAO.class);
	private SessionFactory sf;
	private Session session;

	public SessionFactory getSf() {
		return sf;
	}

	public void setSf(SessionFactory sf) {
		this.sf = sf;
	}

	public void beginTransaction() {
		logger.debug("begin beginTransaction");
		this.session = sf.openSession();
		logger.debug("end beginTransaction");
	}

	public void endTransaction() {
		logger.debug("begin endTransaction");
		sf.close();
		logger.debug("end endTransaction");
	}

	public T save(T t) {
		logger.debug("begin save");
		Object obj = session.save(t);
		logger.debug("end save");
		return (T) obj;
	}

	public T find(int id) {
		logger.debug("end find");
		Object obj = session.createQuery("");
		logger.debug("end find");
		return null;
	}

	public T update(T t) {
		logger.debug("end update");
		session.update(t);
		logger.debug("end update");
		return null;
	}

	public void delete(T t) {
		logger.debug("end delete");
		session.delete(t);
		logger.debug("end delete");
	}
}
